package com.yd.app.mapper.provider;


import com.yd.domain.searchParam.UserSearchParam;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * Created by zg
 */

public class UserProvider extends BaseProvider{


    //查询用户信息list
    public String getUserList(Map map){
        UserSearchParam searchParam = (UserSearchParam)map.get("model");
        StringBuffer buffer = new StringBuffer();
        buffer.append("select sys_user.* FROM sys_user ");
        //添加条件
        buffer.append(this.buildSearchUserSqlConditions(searchParam));
        addFenyeSql(buffer);
        return buffer.toString();
    }
    ///查询用户信息list  Count
    public String getUserListCount(Map map){
        UserSearchParam searchParam = (UserSearchParam)map.get("model");
        StringBuffer buffer = new StringBuffer();
        buffer.append("select count(sys_user.id) FROM sys_user ");
        //添加条件
        buffer.append(this.buildSearchUserSqlConditions(searchParam));
        return buffer.toString();
    }
    private String buildSearchUserSqlConditions(UserSearchParam param){
        StringBuilder buffer = new StringBuilder(" where 1=1");
        if(!StringUtils.isEmpty(param.getUserName())){
            buffer.append(" AND userName like '%"+param.getUserName()+"%'");
        }
        if(!StringUtils.isEmpty(param.getRealName())){
            buffer.append(" AND realName like '%"+param.getRealName()+"%'");
        }
        if(!StringUtils.isEmpty(param.getCompanyName())){
            buffer.append(" AND companyName like '%"+param.getCompanyName()+"%'");
        }
        if(!StringUtils.isEmpty(param.getXydm())){
            buffer.append(" AND xydm like '%"+param.getXydm()+"%'");
        }
        if(!StringUtils.isEmpty(param.getCheckStatus())){
            buffer.append(" and checkStatus='"+param.getCheckStatus()+"' ");
        }
        if(!StringUtils.isEmpty(param.getPhone())){
            buffer.append(" AND phone like '%"+param.getPhone()+"%'");
        }
        if(!StringUtils.isEmpty(param.getPhonePlace())){
            buffer.append(" AND phonePlace like '%"+param.getPhonePlace()+"%'");
        }
        buffer.append(" order by registTime desc ");
        return buffer.toString();
    }
}
